package cn.webestar.scms.user.api.dto.Log;

import cn.webestar.scms.commons.api.SimpleBody;
import cn.webestar.scms.user.entity.Log;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Date;

@Data
@Schema(description = "LogSimpleDTO")
public class LogSimpleDTO extends SimpleBody {

    @Schema(description = "租户id")
    private Long cid;

    @Schema(description = "事件触发者")
    private String actor;

    @Schema(description = "触发者ip")
    private String actorIp;

    @Schema(description = "触发者类型，1：系统，2：员工，3：用户")
    private Integer actorType;

    @Schema(description = "事件产生时间")
    private Date eventTime;

    @Schema(description = "事件描述")
    private String eventDesc;

    @Schema(description = "创建时间")
    private Date createTime;

    @Override
    public LambdaQueryWrapper<Log> toQueryWapper() {
        LambdaQueryWrapper<Log> queryWrapper = new LambdaQueryWrapper<>();
        if (cid!=null) {
            queryWrapper.eq(Log::getCid, cid);
        }
        if (StringUtils.hasText(actor)) {
            queryWrapper.eq(Log::getActor, actor);
        }
        if (StringUtils.hasText(actorIp)) {
            queryWrapper.eq(Log::getActorIp, actorIp);
        }
        if (actorType!=null) {
            queryWrapper.eq(Log::getActorType, actorType);
        }
        if (eventTime!=null) {
            queryWrapper.eq(Log::getEventTime, eventTime);
        }
        if (StringUtils.hasText(eventDesc)) {
            queryWrapper.eq(Log::getEventDesc, eventDesc);
        }
        if (createTime!=null) {
            queryWrapper.eq(Log::getCreateTime, createTime);
        }
        return queryWrapper;
    }

}
